#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
LL a[maxn];
map<LL,LL>map1;
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n;cin>>n;
    map1.clear();
    for(LL i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n==1){
        cout<<0<<endl;continue;
    }
    map1[a[1]]=0;
    for(LL i=2;i<=n;i++){
        if(a[i-1]!=a[i]) map1[a[i]]++;
    }
    LL mx=1e18;
    for(auto i:map1){
        if(i.first!=a[n]){
            map1[i.first]++;
        }
    }
    for(auto i:map1){
        mx=min(mx,i.second);
    }
    if(mx==1e18) cout<<0<<endl;
    else cout<<mx<<endl;
  }
return 0;
}
